home *** CD-ROM | disk | FTP | other *** search
-
- #include <stdlib.h>
- #include <stdio.h>
- #include <string.h>
- #include "cgilib.h"
-
- void main(int argc, char *argv[])
- {
- /* Variables for the data. */
-
- char *data = (char *) 0;
- Dictionary dataDict = 0;
- const char *choice = 0, *title = 0;
- FILE *in = 0;
- char buffer[1024];
- int actual = 0;
- int i;
-
- /* Write the content type */
-
- printf("Content-type: text/html\n\n");
-
- /*
- * Create a dictionary to hold the data.
- */
-
- dataDict = dict_alloc();
-
- /*
- * Read the data, passing the string data by reference.
- * readData() will alloc space for it. readData() will also determine
- * the request type.
- */
-
- readData(&data);
-
- /*
- * Call parseData() to break the data into key-value pairs.
- * This function will print the pairs.
- */
- if(data) parseData(data,dataDict);
-
- choice = (const char *)dict_valueForKey(dataDict,"choice");
-
- if(choice && !strcmp(choice,"library"))
- {
- in = fopen("cgilib.c","r");
- title = "CGI input library";
- }
- else
- {
- in = fopen("dynhtm.c","r");
- title = "dynhtm.pl script";
- }
-
- /* output the HTML header */
- printf("<HTML>\n");
- printf("<HEAD>\n");
-
-
- printf("<TITLE>%s</TITLE>\n",title);
-
-
- printf("</HEAD>\n");
- printf("<BODY>\n");
- printf("<PRE>\n");
-
- while(in && !feof(in))
- {
- actual = fread(buffer,sizeof(char),1024,in);
-
- /* Output the file, converting special characters along the way. */
- i = 0;
- while(buffer[i] && (i<actual))
- {
- if(buffer[i] == '\"')
- {
- printf(""");
- }
- else if(buffer[i] == '&')
- {
- printf("&");
- }
- else if(buffer[i] == '>')
- {
- printf(">");
- }
- else if(buffer[i] == '<')
- {
- printf("<");
- }
- else
- {
- putc(buffer[i],stdout);
- }
-
- i++;
- }
- }
-
- /* Output the html footer */
- printf("</PRE>\n");
- printf("</BODY>\n");
- printf("</HTML>\n");
-
- fclose(in);
- if(data) free(data);
-
- dict_free(dataDict);
-
- /* End the program */
- exit(0);
- }
-
-